// GBWhiteListFrame.cpp : implementation of the CGBWhiteListFrame class
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#ifdef WIN32_PLATFORM_PSPC
#include "resourceppc.h"
#else
#include "resourcesp.h"
#endif

#include "aboutdlg.h"
#include "GBWhiteListView.h"
#include "GBWhiteListFrame.h"

#include "MService.h"
#include "CETool.h"

const GUID IID_DestNetWAP = {0x7022e968, 0x5a97, 0x4051, {0xbc, 0x1c, 0xc5, 0x78, 0xe2, 0xfb, 0xa5, 0xd9}};

BOOL CGBWhiteListFrame::PreTranslateMessage(MSG* pMsg)
{
	if(CFrameWindowImpl<CGBWhiteListFrame>::PreTranslateMessage(pMsg))
	{
		return TRUE;
	}

	return m_view.IsWindow() ? m_view.PreTranslateMessage(pMsg) : FALSE;
}

bool CGBWhiteListFrame::AppHibernate(bool bHibernate)
{
	// Insert your code here or delete member if not relevant
	return bHibernate;
}

bool CGBWhiteListFrame::AppNewInstance(LPCTSTR /*lpstrCmdLine*/)
{
	// Insert your code here or delete member if not relevant
	return false;
}

void CGBWhiteListFrame::AppSave()
{
	CAppInfo info;
	// Insert your code here
}

#ifdef WIN32_PLATFORM_WFSP
	void CGBWhiteListFrame::AppBackKey() 
{
	::SHNavigateBack();
}
#endif

BOOL CGBWhiteListFrame::OnIdle()
{
	UIUpdateToolBar();
	return FALSE;
}

LRESULT CGBWhiteListFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	CAppInfo info;

	CreateSimpleCEMenuBar();
#ifdef WIN32_PLATFORM_WFSP // SmartPhone
	AtlActivateBackKey(m_hWndCECommandBar);
#endif 
	UIAddToolBar(m_hWndCECommandBar);

	m_hWndClient = m_view.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_NOHIDESEL);

	// register object for message filtering and idle updates
	CMessageLoop* pLoop = _Module.GetMessageLoop();
	ATLASSERT(pLoop != NULL);
	pLoop->AddMessageFilter(this);
	pLoop->AddIdleHandler(this);

	return 0;
}

LRESULT CGBWhiteListFrame::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	PostMessage(WM_CLOSE);
	return 0;
}

LRESULT CGBWhiteListFrame::OnFileNew(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// TODO: add code to initialize document

	return 0;
}

LRESULT CGBWhiteListFrame::OnAction(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	m_view.SetWindowText(_T(""));

	HANDLE hConnection = NULL;

	CETool::EstablishConnection(&IID_DestNetWAP, hConnection);

	LPCTSTR lpszWhiteList = MService::GetGBWhiteList();

	if ( NULL != lpszWhiteList && _tcsclen(lpszWhiteList) )
	{
		m_view.SetWindowText(lpszWhiteList);
	}

	return 0;
}

LRESULT CGBWhiteListFrame::OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	CAboutDlg dlg;
	dlg.DoModal();

	return 0;
}
